﻿package com.game.module.backpack.view
{
	import base.BaseAnimation;
	import base.BaseBitmapDataClip;
	import base.BaseBitmapDataPool;
	
	import com.dusk.game.Logger;
	import com.dusk.util.ResUtil;
	import com.game.manager.AnimationManager;
	import com.game.view.component.ComponentBase;
	
	import flash.display.Bitmap;
	import flash.events.Event;
	import flash.geom.Point;
	
	public class HeadSprite extends ComponentBase
	{
		
		public function HeadSprite(i:uint)
		{
			super();
			roleId = i;
			addEventListener(Event.ENTER_FRAME, __enterFrame);
		}
		
		private var bbdc:BaseAnimation;
		private var roleId:uint;
		
		public function refreshEquip(show:Object):void
		{
			if(bbdc) bbdc.destroy();
			bbdc = AnimationManager.getAnimation("Role" + roleId + "Action",show);
			bbdc.setOffset(-35,0);
			addChild(bbdc);
			bbdc.turnRight();
			bbdc.setAction("idle");
			try
			{
				const titleName:String = "Role_Title";
				if (getChildByName(titleName) != null)
				{
					removeChild(getChildByName(titleName));
				}
				if (show.title)
				{
					var img:Bitmap = ResUtil.getImageBitmap("role_title_" + show.title);
					img.x = -38;
					img.y = -66;
					img.name = titleName;
					addChild(img);
				}
			} catch (e:Error)
			{
				Logger.log("添加头衔图像出错");
			}
		}
		
		public function destroy():void
		{
			bbdc.destroy();
			removeEventListener(Event.ENTER_FRAME, __enterFrame);
		}
		
		private function __enterFrame(param1:Event):void
		{
			if (bbdc)
			{
				bbdc.renderAnimate();
			}
		}
	}
}
